//
//  AppDelegate.m
//  OCsinaBlog
//
//  Created by jobo on 16/4/23.
//  Copyright © 2016年 jobo. All rights reserved.
//

#import "AppDelegate.h"
#import "JBTabBarController.h"
#import "JBNewfeatureViewController.h"
#import "JBOAuthViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //阻塞一下线程,延迟欢迎界面时间
    [NSThread sleepForTimeInterval:2] ;
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 
    //设置uiwindow
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] ;
    //设置uiwindow 的根控制器
    
    //新特性界面控制器
    JBNewfeatureViewController *newVc = [[JBNewfeatureViewController alloc] init] ;
    //主界面控制器
    JBTabBarController *tabarRootViewController = [[JBTabBarController alloc] init] ;
    
    
    
    //获取沙盒版本号
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *defaultVersion = [defaults stringForKey:@"currenVersion"];
    //获取当前版本号
    NSString *currenVersion = [[[NSBundle mainBundle] infoDictionary]objectForKey:(NSString *)kCFBundleVersionKey];
    //是否第一次使用
    if(defaults == nil)
    {
         self.window.rootViewController = newVc ;
    }
    //是否更新了版本
    else if ((int)defaultVersion < (int)currenVersion)
    {
         self.window.rootViewController = newVc ;
    }
    //不是的话就直接进入主界面
    else
    {
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"] != nil)
        {
            NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"expires_in"]);
            NSLog(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"remind_in"]);
            self.window.rootViewController = tabarRootViewController;
        }
        else
        {
            JBOAuthViewController *oauthVc = [[JBOAuthViewController alloc] init];
            self.window.rootViewController = oauthVc ;
        }
    }
    //设置为主key并显示
    [self.window makeKeyAndVisible] ;
    
    
    
    return YES;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
